<!-- 在线网页编辑器引入 -->
<link rel="stylesheet" href="/static/kindeditor/themes/default/default.css" />
<script src="/static/kindeditor/kindeditor-all-min.js"></script>
<script src="/static/kindeditor/lang/zh-CN.js"></script>
<script>
	var editor;
	KindEditor.ready(function (K) {
		editor = K.create('textarea[name="content"]', {
			allowFileManager: true,
		});
	});
</script>

<div class="layui-hide-xs">
	<div class="fly-panel fly-column">
		<div class="layui-container">
			<ul class="layui-clear">
				<li class="layui-hide-xs {$cateid == 0 ? 'layui-this' : ''}"><a href="/">全部</a></li>
				{foreach $catelist as $cate}
				<li class="{$cateid == $cate['id'] ? 'layui-this' : ''}">
					<a href="{:url('home/index/index',['cateid' => $cate['id']])}">{$cate['name']}</a>
				</li>
				{/foreach}

				<!-- 用户登入后显示 -->
				<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
					<a href="{:url('home/post/index')}">我发表的贴</a>
				</li>
				<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block">
					<a href="{:url('home/post/collect')}">我收藏的贴</a>
				</li>
			</ul>

			<div class="fly-column-right layui-hide-xs">
				<span class="fly-search"><i class="layui-icon"></i></span>
				<a href="add.html" class="layui-btn">发表新帖</a>
			</div>
			<div
				class="layui-hide-sm layui-show-xs-block"
				style="margin-top: -10px; padding-bottom: 10px; text-align: center"
			>
				<a href="add.html" class="layui-btn">发表新帖</a>
			</div>
		</div>
	</div>
</div>

<div class="layui-container">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md8 content detail">
			<div class="fly-panel detail-box">
				<h1>{$postinfo.title}</h1>
				<div class="fly-detail-info">
					{if condition="$postinfo.accept"}
					<span class="layui-badge" style="background-color: #5fb878">已结</span>
					{else /}
					<span class="layui-badge" style="background-color: #999">未结</span>
					{/if} {if condition="$postinfo.state == 1"}
					<span class="layui-badge layui-bg-red">置顶</span>
					{elseif condition="$postinfo.state == 2"}
					<span class="layui-badge layui-bg-red">精华</span>
					{elseif condition="$postinfo.state == 3"}
					<span class="layui-badge layui-bg-red">热门</span>
					{/if}

					<div class="fly-admin-box" data-id="123">
						{if condition="$postinfo.user.id == $Think.cookie.LoginUser['id']"}
						<span class="layui-btn layui-btn-xs jie-admin" type="del" id="del">删除</span>
						{/if}

						<!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="1">置顶</span>  -->
						<!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="stick" rank="0" style="background-color:#ccc;">取消置顶</span> -->

						<!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="1">加精</span>  -->
						<!-- <span class="layui-btn layui-btn-xs jie-admin" type="set" field="status" rank="0" style="background-color:#ccc;">取消加精</span> -->
					</div>
					<span class="fly-list-nums">
						<a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> {$count}</a>
						<i class="iconfont" title="人气">&#xe60b;</i> {$VisitCount}
					</span>
				</div>
				<div class="detail-about">
					<a
						class="fly-avatar"
						href="{:url('home/user/index', ['userid' => $postinfo['user']['id']])}"
					>
						{if condition="$postinfo['user']['avatar']"}
						<img src="/{$postinfo['user']['avatar']}" />
						{else /}
						<img src="/assets/home/images/avatar.jpg" />
						{/if}
					</a>
					<div class="fly-detail-user">
						<a href="../user/home.html" class="fly-link">
							<cite>{$postinfo['user']['nickname']}</cite>
							{if condition="$postinfo['user']['auth'] == 1"}
							<i class="iconfont icon-renzheng" title="认证信息：{{ rows.user.approve }}"></i>
							{/if} {if condition="$postinfo['user']['vip'] > 0"}
							<i class="layui-badge fly-badge-vip">VIP</i>
							{/if}
						</a>
						<span>{$postinfo.createtime}</span>
					</div>
					<div class="detail-hits" id="LAY_jieAdmin" data-id="123">
						<span style="padding-right: 10px; color: #ff7200">悬赏：{$postinfo.point}积分</span>
						{if condition="$postinfo.user.id == $Think.cookie.LoginUser['id']"}
						<span class="layui-btn layui-btn-xs jie-admin" type="edit"
							><a href="{:url('home/post/edit', ['postid' => $postinfo.id])}">编辑此贴</a></span
						>
						{/if}

						<!-- 收藏 -->
						{if condition="$Think.cookie.LoginUser"} {if condition="$CollectStatus"}
						<span
							class="layui-btn layui-btn-xs jie-admin layui-bg-black"
							type="edit"
							id="CollectDel"
						>
							<a href="javascript:void(0)">取消收藏</a>
						</span>
						{else /}
						<span
							class="layui-btn layui-btn-xs jie-admin layui-bg-blue"
							type="edit"
							id="CollectAdd"
						>
							<a href="javascript:void(0)">收藏</a>
						</span>
						{/if} {/if}
					</div>
				</div>
				<div class="detail-body photos">
					<p>{$postinfo.content}</p>
				</div>
			</div>

			<div class="fly-panel detail-box" id="flyReply">
				<fieldset class="layui-elem-field layui-field-title" style="text-align: center">
					<legend>回帖</legend>
				</fieldset>

				<ul class="jieda" id="jieda">
					{if condition="$commentlist"} {:CommentHtml($commentlist,$postinfo)} {else}
					<!-- 无数据时 -->
					<li class="fly-none">消灭零回复</li>
					{/if}
				</ul>

				<!-- 评论的表单 -->
				{if condition="!$postinfo['accept'] AND $Think.cookie.LoginUser"}
				<div class="layui-form layui-form-pane">
					<form action="{:url('home/comment/add')}" method="post">
						<div class="layui-form-item layui-form-text">
							<h2 id="reply-name"></h2>
							<div class="layui-input-block">
								<textarea
									id="content"
									name="content"
									class="layui-textarea"
									style="height: 300px"
								></textarea>
							</div>
						</div>
						<div class="layui-form-item">
							<input type="hidden" name="postid" value="{$postinfo.id}" />
							<input type="hidden" name="pid" value="" />
							<button class="layui-btn" type="submit">提交回复</button>
						</div>
					</form>
				</div>
				{/if}
			</div>
		</div>
		<div class="layui-col-md4">
			<dl class="fly-panel fly-list-one">
				<dt class="fly-panel-title">本周热议</dt>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>
				<dd>
					<a href="">基于 layui 的极简社区页面模版</a>
					<span><i class="iconfont icon-pinglun1"></i> 16</span>
				</dd>

				<!-- 无数据时 -->
				<!--
           <div class="fly-none">没有相关数据</div>
           -->
			</dl>

			<div class="fly-panel">
				<div class="fly-panel-title">这里可作为广告区域</div>
				<div class="fly-panel-main">
					<a
						href="http://layim.layui.com/?from=fly"
						target="_blank"
						class="fly-zanzhu"
						time-limit="2017.09.25-2099.01.01"
						style="background-color: #5fb878"
						>LayIM 3.0 - layui 旗舰之作</a
					>
				</div>
			</div>

			<div class="fly-panel" style="padding: 20px 0; text-align: center">
				<img src="../../res/images/weixin.jpg" style="max-width: 100%" alt="layui" />
				<p style="position: relative; color: #666">微信扫码关注 layui 公众号</p>
			</div>
		</div>
	</div>
</div>
<script>
	layui.use('layer', function () {
		var layer = layui.layer;
		var $ = layui.jquery;

		// 添加收藏
		$('#CollectAdd').click(function () {
			$.ajax({
				type: 'POST',
				url: `{:url('home/collect/add')}`,
				data: `postid={$postinfo.id}`,
				dataType: 'json',
				success: function (data) {
					if (data.result) {
						//成功
						layer.msg(
							data.msg,
							{
								icon: 1,
								time: 2000, //2秒关闭（如果不配置，默认是3秒）
							},
							function () {
								//直接刷新界面
								location.reload();
							}
						);
					} else {
						//失败
						layer.msg(data.msg);
					}
				},
			});
		});

		//取消收藏
		$('#CollectDel').click(function () {
			$.ajax({
				type: 'POST',
				url: `{:url('home/collect/del')}`,
				data: `postid={$postinfo.id}`,
				dataType: 'json',
				success: function (data) {
					if (data.result) {
						//成功
						layer.msg(
							data.msg,
							{
								icon: 1,
								time: 2000, //2秒关闭（如果不配置，默认是3秒）
							},
							function () {
								//直接刷新界面
								location.reload();
							}
						);
					} else {
						//失败
						layer.msg(data.msg);
					}
				},
			});
		});

		// 删除帖子
		$('#del').click(function () {
			layer.confirm(
				'是否确认删除',
				{
					icon: 3,
					title: '提示',
				},
				function (index) {
					//关闭弹框
					layer.close(index);

					$.ajax({
						type: 'POST',
						url: `{:url('home/post/delete')}`,
						data: `postid={$postinfo.id}`,
						dataType: 'json',
						success: function (data) {
							if (data.result) {
								//成功
								layer.msg(
									data.msg,
									{
										icon: 1,
										time: 2000, //2秒关闭（如果不配置，默认是3秒）
									},
									function () {
										location.href = "{:url('home/index/index')}";
										return false;
									}
								);
							} else {
								//删除失败
								layer.msg(data.msg);
							}
						},
					});
				}
			);
		});

		// 点击回复
		$('.reply').click(function () {
			var pid = $(this).data('pid');
			var nickname = $(this).data('nickname');
			$('#reply-name').html('回复给：' + nickname);
			$("input[name='pid']").val(pid);
		});

		// 点赞
		$('.thumbs').click(function () {
			var id = $(this).data('id');

			$.ajax({
				type: 'POST',
				url: `{:url('home/comment/thumbs')}`,
				data: `id=${id}`,
				dataType: 'json',
				success: function (data) {
					if (data.result) {
						//成功
						layer.msg(
							data.msg,
							{
								icon: 1,
								time: 2000, //2秒关闭（如果不配置，默认是3秒）
							},
							function () {
								//直接刷新界面
								location.reload();
							}
						);
					} else {
						//失败
						layer.msg(data.msg);
					}
				},
			});
		});

		//采纳
		$('.accept').click(function () {
			var comid = $(this).data('comid');

			$.ajax({
				type: 'POST',
				url: `{:url('home/comment/accept')}`,
				data: `comid=${comid}`,
				dataType: 'json',
				success: function (data) {
					if (data.result) {
						//成功
						layer.msg(
							data.msg,
							{
								icon: 1,
								time: 2000, //2秒关闭（如果不配置，默认是3秒）
							},
							function () {
								//直接刷新界面
								location.reload();
							}
						);
					} else {
						//失败
						layer.msg(data.msg);
					}
				},
			});
		});
	});
</script>
